package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.HlsSysFile;
import com.bestow.basic.service.IHlsSysFileService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 关联附件Controller
 *
 * @author liliu
 * @date 2022-10-05
 */
@RestController
@RequestMapping("/basic/sysFile")
public class HlsSysFileController extends BaseController {
    @Autowired
    private IHlsSysFileService hlsSysFileService;

    /**
     * 查询关联附件列表
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlsSysFile hlsSysFile) {
        startPage();
        List<HlsSysFile> list = hlsSysFileService.selectHlsSysFileList(hlsSysFile);
        return getDataTable(list);
    }

    /**
     * 导出关联附件列表
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:export')")
    @Log(title = "关联附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlsSysFile hlsSysFile) {
        List<HlsSysFile> list = hlsSysFileService.selectHlsSysFileList(hlsSysFile);
        ExcelUtil<HlsSysFile> util = new ExcelUtil<HlsSysFile>(HlsSysFile.class);
        util.exportExcel(response, list, "关联附件数据");
    }

    /**
     * 获取关联附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return AjaxResult.success(hlsSysFileService.selectHlsSysFileByFileId(fileId));
    }

    /**
     * 新增关联附件
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:add')")
    @Log(title = "关联附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlsSysFile hlsSysFile) {
        return toAjax(hlsSysFileService.insertHlsSysFile(hlsSysFile));
    }

    /**
     * 修改关联附件
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:edit')")
    @Log(title = "关联附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlsSysFile hlsSysFile) {
        return toAjax(hlsSysFileService.updateHlsSysFile(hlsSysFile));
    }

    /**
     * 删除关联附件
     */
    @PreAuthorize("@ss.hasPermi('basic:sysFile:remove')")
    @Log(title = "关联附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(hlsSysFileService.deleteHlsSysFileByFileIds(fileIds));
    }
}
